# Upload project to Gitee
Write-Host "=== Upload Project to Gitee ===" -ForegroundColor Green

# Check if Git is available
try {
    git --version
    Write-Host "Git is installed" -ForegroundColor Green
} catch {
    Write-Host "Error: Git is not installed or not in PATH. Please restart PowerShell or restart computer." -ForegroundColor Red
    exit 1
}

# 1. Initialize Git repository
Write-Host "1. Initializing Git repository..." -ForegroundColor Yellow
git init

# 2. Configure Git user info (if not configured)
Write-Host "2. Configuring Git user info..." -ForegroundColor Yellow
$userName = Read-Host "Please enter your Git username"
$userEmail = Read-Host "Please enter your Git email"

git config --global user.name "$userName"
git config --global user.email "$userEmail"

# 3. Add all files to staging area
Write-Host "3. Adding files to staging area..." -ForegroundColor Yellow
git add .

# 4. Commit code
Write-Host "4. Committing code..." -ForegroundColor Yellow
$commitMessage = @"
Initial commit: Spring Boot + Vue.js User Login System

Features:
- Spring Boot 3.x + Spring Security
- JWT Authentication
- Vue.js 3 Frontend
- MySQL Database Support
- Complete Unit Testing
- Service Layer Refactoring with Single Responsibility Principle
- Global Exception Handling
- Async Notification Service
- Audit Logging

Tech Stack:
- Backend: Spring Boot, Spring Security, JPA, JWT
- Frontend: Vue.js 3, Element Plus
- Database: MySQL, H2(Test)
- Testing: JUnit 5, Mockito, JaCoCo
- Build: Maven
"@

git commit -m $commitMessage

# 5. Add remote repository
Write-Host "5. Adding remote repository..." -ForegroundColor Yellow
$giteeUrl = Read-Host "Please enter your Gitee repository URL (e.g., https://gitee.com/your-username/your-repo.git)"

git remote add origin $giteeUrl

# 6. Push to remote repository
Write-Host "6. Pushing to remote repository..." -ForegroundColor Yellow
Write-Host "First push may require Gitee username and password..." -ForegroundColor Cyan

try {
    git push -u origin master
    Write-Host "Project successfully uploaded to Gitee!" -ForegroundColor Green
} catch {
    Write-Host "Push failed, trying with main branch..." -ForegroundColor Yellow
    git branch -M main
    git push -u origin main
    Write-Host "Project successfully uploaded to Gitee!" -ForegroundColor Green
}

Write-Host "Upload completed! You can view your project on Gitee now." -ForegroundColor Green